/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'
import { Swiper } from '@tarojs/components'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Toast} from '../../library/func';
import Icon from '../../project/style/icon';
import Http from '../../project/func/http/http'

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class HomeIndex extends Component {

	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			// 获取屏幕高度
            scrollHeight: wx.getSystemInfoSync().windowHeight,
            // 用户数据
            user:{},
            // 判断是否为 管理员
            is_master:false,
            
		}
	}
	/*------------------------------------------------------------------------------------
	 * 声明周期
	 *-----------------------------------------------------------------------------------*/
      componentWillMount () {
        this.getUserInfo()
      }

      componentDidMount() {
        this.getUserInfo()
      }

    /*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
    // onRedirect
    onRedirect(url){
        wx.redirectTo({
            url: url
        })
    }
    // onNavigate
    onNavigate(url){
        wx.navigateTo({
            url: url
        })
    }
    //onNavigateBack
    onNavigateBack(num=1){
        wx.navigateBack({
            delta: num
        })                    
    }

    /*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
    // 获取用户接口
    getUserInfo(){

        // 判断是否为 管理员
        Http.AuthOk((res)=>{
            this.setState({
                is_master:res,
            })
        })

        // 获取用户数据
        Http.Loading({
            url:'center/index.php',
            success:(data)=>{
                this.setState({
                    user:data.system.object
                })
                console.log(data)
            }
        })
	}

    // 轻提示 toToast
    toToast(){
        Toast.text('暂未开启此功能')
    }

    config = {
        navigationBarBackgroundColor: '#ceb852',
        navigationBarTitleText: '我的',
        navigationBarTextStyle: '#fff'
    }

	/**
	 * 渲染
	 */
	render() {

		// 渲染
		return (
			<CPage>
				<CContent>
                    <CColumn>
                        {/* 顶部 */}
                        <CRow bg='#ceb852' h='160' rb='20' x='center'>
                            <CItemY>
                                <CImage src={this.state.user.set_logo} w='75' h='75' ra='50' ba='4 solid #ece184' mt='-10'/>
                                <CHand size='18' color='#fff' mt='10'>{this.state.user.set_name}</CHand>
                            </CItemY>
                        </CRow>

                        {/* 活动报名、我的收藏 */}
                        <CRow bg='#fff' mx='20' mt='-10' ra='15'>
                            <CBetween>
                                <CLine py='15' px='30'>
                                    <CItemY mt='10' onClick={this.toToast}>
                                        <CSvg icon={Icon.flag} color='#7c7c7c' w='24' h='24'></CSvg>
                                        <CHand rel mt='10'>
                                            <CText size='15' mr='10' color='#2e2e2e'>我的活动</CText>
                                            {/*<CHand w='5' h='5' bg='#f00' ra='50' abs right='0' top='0'></CHand>*/}
                                        </CHand>
                                    </CItemY>
                                </CLine>
                                <CLine py='15' px='30' x='right'>
                                    <CItemY mt='10' onClick={this.onNavigate.bind(this,'/screen/user/collect')}>
                                        <CSvg icon={Icon.collect} color='#7c7c7c' w='24' h='24'></CSvg>
                                        <CText size='15' mt='10' color='#2e2e2e'>我的收藏</CText>
                                    </CItemY>
                                </CLine>
                            </CBetween>
                        </CRow>

                        {/* 菜单 */}
                        {
                            this.state.is_master && (
                                <CRow bg='#fff' mt='16' >
                                    <CAround mx='10' my='20'>
                                        <CLine x='center' br='1 solid #f0f0f0' pa='10'>
                                            <CItemY onClick={this.toToast}>
                                                <CSvg icon={Icon.caogao} color='#7c7c7c' w='26' h='26'></CSvg>
                                                <CText color='#2e2e2e' size='14' mt='10'>我的草稿</CText>
                                            </CItemY>
                                        </CLine>
                                        <CLine x='center' pa='10'>
                                            <CItemY onClick={this.toToast}>
                                                <CSvg icon={Icon.shareaf} color='#7c7c7c' w='26' h='26'></CSvg>
                                                <CText color='#2e2e2e' size='14' mt='10'>分享</CText>
                                            </CItemY>
                                        </CLine>
                                    </CAround>
                                </CRow>
                            )
                        }
                        
                    </CColumn>
				</CContent>
			</CPage>
		);
	}
};